import org.authsum.stitches.Helper


class FoldersControllerTests extends GroovyTestCase {
	def helper

    def stitchesService
	
	void testDeleteFolder() {
		

		Long folderId = helper.getFolderId(name:"testDeleteFolder")
		
		
		def controller = new FoldersController()	
    	controller.stitchesService  = stitchesService
		controller.request.parameters = ['folderId':folderId.toString()]
		controller.deleteFolder()
	}
	
	
	void testAddFolderToTag() {
		Long folderId = helper.getFolderId(name:"testAddFolderToTag")
		

		Long tagId = helper.getTagId(name:"testAddFolderToTag")
		
		
		
		def controller = new FoldersController()	
    	controller.stitchesService  = stitchesService
		controller.request.parameters = ['folderId':folderId.toString(),'tagId':tagId.toString()]
		controller.addFolderToTag()
		
		
	}
	
	
	void testAddFolderToContent() {
		//create contentdef
		Long contentDefId = helper.getContentDefId(name:"testAddFolderToContent")
		Long contentId = helper.getContentId(contentDefId:contentDefId,name:"testAddFolderToContent")
		
		

		

		Long folderId = helper.getFolderId(name:"testAddFolderToContent")
		def controller = new FoldersController()	
    	controller.stitchesService  = stitchesService
		controller.request.parameters = ['folderId':folderId.toString(),'contentId':contentId.toString()]
		controller.addFolderToContent()
		
	}
	
	
	
	void testAddChildFolder() {

		Long pfolderid = helper.getFolderId(name:"testAddChildFolder 1")
		
		
		Long cfolderid = helper.getFolderId(name:"testAddChildFolder 2")
		
		def controller = new FoldersController()	
    	controller.stitchesService  = stitchesService
		controller.request.parameters = ['folderId':pfolderid.toString(),'childFolderId':cfolderid.toString()]
		controller.addChildFolder()
	}
	
	void testFindChildFolders() {
		
		Long pfolderid = helper.getFolderId(name:"testFindChildFolders 1")
		
		
		
		Long cfolderid = helper.getFolderId(name:"testFindChildFolders 2")
		
		helper.addChildFolder(pfolderid,cfolderid)
		
		Long cfolderid2 = helper.getFolderId(name:"testFindChildFolders 3")
		helper.addChildFolder(pfolderid,cfolderid2)
			def controller = new FoldersController()	
    	controller.stitchesService  = stitchesService
		controller.request.parameters = ['folderId':pfolderid.toString()]
		controller.findChildFolders()   	
		
	}
	
	
	
	void testEditFolder() {
		
		Long folderId = helper.getFolderId(name:"testEditFolder")
		
			def controller = new FoldersController()	
    	controller.stitchesService  = stitchesService
		controller.request.parameters = ['folderId':folderId.toString()]
		controller.editFolder()
		
	}
	
	
	void testSaveNewFolder() {
		def controller = new FoldersController()	
    	controller.stitchesService  = stitchesService
		controller.request.parameters = ['name':"testSaveNewFolder"]
		controller.saveFolder()  
	}
	
	void testSaveExistingFolder() {
		Long folderId = helper.getFolderId(name:"testSaveExistingFolder")
		
		
		def controller = new FoldersController()
    	controller.stitchesService  = stitchesService
		//controller.helper = helper
		controller.request.parameters = ['name':"testSaveExistingFolder2",id:folderId.toString()]
		controller.saveFolder()  
		//let's verify it worked
		def folderHolder = helper.findFolderById(folderId)
		println folderHolder
		assertTrue folderHolder.name == 'testSaveExistingFolder2'
			
	}
	
	
	
	void testIndex() {
		def controller = new FoldersController()	
    	controller.stitchesService  = stitchesService
		controller.index()   	
	}
}
